package com.tjbklx1.redis.me;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisConnection {

	
	private static JedisPool pool = null;

	public synchronized static JedisPool getPool() {
		if (pool == null) {
//			pool = new JedisPool(null,"localhost", 6379,100000,null,4);
			pool = new JedisPool("localhost", 6379);
			
//			JedisPoolConfig config = new JedisPoolConfig();
//            config.setMaxTotal(MAX_ACTIVE);//最大连接数
//            config.setMaxIdle(MAX_IDLE);//最大空闲连接数
//            config.setMaxWaitMillis(MAX_WAIT);//获取可用连接的最大等待时间
//			pool.initPool(config, factory);
		}
		return pool;
	}
	
	/**
	 * 返还到连接池
	 * 
	 * @param pool
	 * @param redis
	 */
	public static void returnResource(JedisPool pool, Jedis redis) {
		if (redis != null) {
//			pool.returnResource(redis);
			redis.close();
		}
	}
}
